package service;

import java.util.List;

import dao.CartDao;
import dao.CartDaoa;
import pojo.Cart;
import pojo.PageBean;

public class CartServicea {
	public int updateCartOrderId(int cid,String orderid) {
		CartDao cdao=new CartDao();
		int flag=cdao.updateCartOrderId(cid, orderid);
		return flag;
	}
	public Cart getOne(String p_id) {
		CartDaoa cdao=new CartDaoa();
		Cart t=cdao.getOne(p_id);
		return t;
	}
	public int addCart(Cart c) {
		CartDaoa cdao=new CartDaoa();
		Cart t = cdao.getOne(c.getP_id());
		int flag=0;
		if(t==null) {
			flag=cdao.addCart(c);
		}else {
			flag=cdao.updateNumber(c);
		}
		return flag;
	}
	public PageBean<Cart> showCarts(int currentPage,int pageSize,String c_name){
		 CartDaoa cdao = new CartDaoa();
	    	PageBean<Cart> pb = new PageBean<Cart>();
	    	int total= cdao.getCount();  //总数
	    	pb.setTotal(total);
	    	int totalPage = (total%pageSize==0)?(total/pageSize):(total/pageSize+1);
	    	pb.setTotalPage(totalPage);
	    	pb.setPageSize(pageSize);
	    	pb.setCurrentPage(currentPage);
	    	List<Cart> list =cdao.showCart(currentPage, pageSize, c_name);
	    	pb.setList(list);
	    	System.out.println("service......"+currentPage+"  "+pageSize);
	    	return pb;
	    	
	    }

}
